package com.study.testShiro.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回信息通用类
 * @author panhu
 *
 */
public class ReturnMsg {

	//返回标记
	private boolean flag;
	
	//返回信息
	private String msg;
	
	//返回数据
	private Map<String, Object> map = new HashMap<String, Object>();

	public boolean isFlag() {
		return flag;
	}

	public void setFlag(boolean flag) {
		this.flag = flag;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Map<String, Object> getMap() {
		return map;
	}

	public void setMap(Map<String, Object> map) {
		this.map = map;
	}
	
	/**
	 * 返回成功信息
	 * @param message
	 * @return
	 */
	public static ReturnMsg success(String message){
		ReturnMsg result = new ReturnMsg();
		result.setFlag(true);
		result.setMsg(message);
		return result;
	}
	
	/**
	 * 返回失败信息
	 * @param message
	 * @return
	 */
	public static ReturnMsg fail(String message){
		ReturnMsg result = new ReturnMsg();
		result.setFlag(false);
		result.setMsg(message);
		return result;
	}
	
	/**
	 * 追加返回数据
	 * @param key
	 * @param value
	 * @return
	 */
	public ReturnMsg add(String key,Object value){
		this.map.put(key, value);
		return this;
	}

	@Override
	public String toString() {
		return "ReturnMsg [flag=" + flag + ", msg=" + msg + ", map=" + map + "]";
	}
	
}
